<template>
	<view class="g-bd">
		<view class="m-wx f-zfs30">
			<view>长按保存图片， <button type="default" size="mini" @click="openWeixin">打开微信</button> 扫一扫关注公众号，即可接收服务到期推送消息。</view>
			<view>或者</view>
			<view>在微信中搜索并关注公众号 <text style="color: #2A9F93;">'安域智慧系统'</text><button type="default" size="mini"
					@click="copy">复制</button>。</view>
			<view style="text-align: center;">
				<image class="u-wx-img" :src="img[0]" mode="" @click="save"></image>
			</view>
		</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				img: [require('../../../static/images/qrcode.jpg')]
			}
		},
		methods: {
			openWeixin() {
				void plus.runtime.openURL("weixin://");
			},
			copy() {
				uni.setClipboardData({
					data: '安域智慧系统',
					success: function() {
						uni.showModal({
							title: '信息复制',
							content: '复制成功',
							cancelText: '取消',
							confirmText: '前往微信搜索',
							success: function(res) {
								if (res.confirm) {
									void plus.runtime.openURL("weixin://");
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				});
			},
			save() {
				var self = this;
				uni.previewImage({
					urls: self.img,
					longPressActions: {
						itemList: ['保存图片'],
						success(res) {
							uni.saveImageToPhotosAlbum({
								filePath: self.img[res.index],
								success() {
									uni.showToast({
										title: '保存成功',
										icon: 'none'
									})
								},
								fail() {
									uni.showToast({
										title: '保存失败,请重试',
										icon: 'none'
									})
								}
							})
						}
					},
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.m-wx {
		margin-top: 30rpx;
		padding: 20rpx;

		button {
			background-color: #2A9F93;
			color: #FFF;
		}

		.u-wx-img {
			width: 400rpx;
			height: 400rpx;
		}
	}
</style>
